package com.mymobile.showcase.mobile;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import com.hmsproject.common.HMSUtil;
import com.hmsproject.db.util.HMSDBUtil;

@ManagedBean
@ViewScoped
public class ForgotPasswordView {
	
	private String emailAddress;

	public String getEmailAddress() {
		return emailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}
	
	public void forgotPassword(ActionEvent event){
		
		try{
			String password = HMSDBUtil.getInstance().forgotPassword(this);
			HMSUtil.getInstance().forgotPassword(this.getEmailAddress(), password);
			FacesContext.getCurrentInstance().addMessage(null, 
			        new FacesMessage(FacesMessage.SEVERITY_INFO, "HMS password sent to " + this.getEmailAddress(), null));		

		}catch(Exception e){
			FacesContext.getCurrentInstance().addMessage(null, 
			        new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), null));
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ForgotPasswordView forgotPasswordView = new ForgotPasswordView();
		forgotPasswordView.setEmailAddress("arumugampillaia@gmail.com");
		forgotPasswordView.forgotPassword(null);
	}

}
